home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP06.ZIP / CHAP06 / COSCHMOO / IADVSINK.CPP < prev    next >
C/C++ Source or Header  |  1993-05-04  |  8KB  |  405 lines

  1. /*
  2.  * IADVSINK.CPP
  3.  * Component Schmoo Chapter 6
  4.  *
  5.  * Implementation of the CPolylineAdviseSink and CImpIAdviseSink interfaces
  6.  * for Component Schmoo.  CPolylineAdviseSink moved here from polyline.cpp
  7.  * to live with all the advise stuff.
  8.  *
  9.  * IAdviseSink is implemented as a stand-alone object since no other piece
  10.  *
  11.  *
  12.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  13.  *
  14.  * Kraig Brockschmidt, Software Design Engineer
  15.  * Microsoft Systems Developer Relations
  16.  *
  17.  * Internet  :  kraigb@microsoft.com
  18.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  19.  */
  20.  
  21.  
  22. #include "coschmoo.h"
  23.  
  24.  
  25. /*
  26.  * CPolylineAdviseSink::CPolylineAdviseSink
  27.  * CPolylineAdviseSink::~CPolylineAdviseSink
  28.  *
  29.  * Constructor Parameters:
  30.  *  pv              LPVOID to store in this object
  31.  *  punkOuter       LPUNKNOWN for IUnknown member delegation
  32.  */
  33.  
  34. CPolylineAdviseSink::CPolylineAdviseSink(LPVOID pv, LPUNKNOWN punkOuter)
  35.     {
  36.     m_cRef=0;
  37.     m_pv=pv;
  38.     m_punkOuter=punkOuter;
  39.     return;
  40.     }
  41.  
  42.  
  43. CPolylineAdviseSink::~CPolylineAdviseSink(void)
  44.     {
  45.     return;
  46.     }
  47.  
  48.  
  49.  
  50.  
  51. /*
  52.  * CPolylineAdviseSink::QueryInterface
  53.  * CPolylineAdviseSink::AddRef
  54.  * CPolylineAdviseSink::Release
  55.  *
  56.  * Purpose:
  57.  *  IUnknown members for this IPolylineAdviseSink implementations.
  58.  */
  59.  
  60. STDMETHODIMP CPolylineAdviseSink::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  61.     {
  62.     return m_punkOuter->QueryInterface(riid, ppv);
  63.     }
  64.  
  65.  
  66. STDMETHODIMP_(ULONG) CPolylineAdviseSink::AddRef(void)
  67.     {
  68.     ++m_cRef;
  69.     return m_punkOuter->AddRef();
  70.     }
  71.  
  72.  
  73. STDMETHODIMP_(ULONG) CPolylineAdviseSink::Release(void)
  74.     {
  75.     --m_cRef;
  76.     return m_punkOuter->AddRef();
  77.     }
  78.  
  79.  
  80.  
  81.  
  82. /*
  83.  * CPolylineAdviseSink::OnPointChange
  84.  *
  85.  * Purpose:
  86.  *  Informs the document that the polyline added or removed a point.
  87.  *
  88.  * Parameters:
  89.  *  None
  90.  *
  91.  * Return Value:
  92.  *  None
  93.  */
  94.  
  95. STDMETHODIMP_(void) CPolylineAdviseSink::OnPointChange(void)
  96.     {
  97.     LPCDocument pDoc=(LPCDocument)m_pv;
  98.  
  99.     pDoc->FDirtySet(TRUE);
  100.     return;
  101.     }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. /*
  109.  * CPolylineAdviseSink::OnSizeChange
  110.  *
  111.  * Purpose:
  112.  *  Informs the document that the polyline changed size.
  113.  *
  114.  * Parameters:
  115.  *  None
  116.  *
  117.  * Return Value:
  118.  *  None
  119.  */
  120.  
  121. STDMETHODIMP_(void) CPolylineAdviseSink::OnSizeChange(void)
  122.     {
  123.     LPCSchmooDoc pDoc=(LPCSchmooDoc)m_pv;
  124.     RECT         rc;
  125.     DWORD        dwStyle;
  126.     HWND         hWnd;
  127.  
  128.     /*
  129.      * Polyline window is informing us that it changed size in
  130.      * response to setting it's data.  Therefore we have to
  131.      * size ourselves accordingly but without moving the screen
  132.      * position of the polyline window.
  133.      */
  134.  
  135.     pDoc->m_fNoSize=TRUE;
  136.  
  137.     //Set the document window size.
  138.     pDoc->m_pPL->Window(&hWnd);
  139.     GetWindowRect(hWnd, &rc);
  140.     InflateRect(&rc, 8, 8);
  141.  
  142.     //Adjust for a window sans menu
  143.     dwStyle=GetWindowLong(pDoc->m_hWnd, GWL_STYLE);
  144.     AdjustWindowRect(&rc, dwStyle, FALSE);
  145.  
  146.     SetWindowPos(pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
  147.         , rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
  148.  
  149.     if (NULL!=pDoc->m_pAdv)
  150.         pDoc->m_pAdv->OnSizeChange(pDoc, &rc);
  151.  
  152.     pDoc->m_fNoSize=FALSE;
  153.     pDoc->FDirtySet(TRUE);
  154.  
  155.     return;
  156.     }
  157.  
  158.  
  159.  
  160.  
  161.  
  162. /*
  163.  * CPolylineAdviseSink::OnColorChange
  164.  *
  165.  * Purpose:
  166.  *  Informs the document that the polyline data changed a color.
  167.  *
  168.  * Parameters:
  169.  *  None
  170.  *
  171.  * Return Value:
  172.  *  None
  173.  */
  174.  
  175. STDMETHODIMP_(void) CPolylineAdviseSink::OnColorChange(void)
  176.     {
  177.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  178.  
  179.     pDoc->FDirtySet(TRUE);
  180.     return;
  181.     }
  182.  
  183.  
  184.  
  185.  
  186.  
  187. /*
  188.  * CPolylineAdviseSink::OnLineStyleChange
  189.  *
  190.  * Purpose:
  191.  *  Informs the document that the polyline changed its line style.
  192.  *
  193.  * Parameters:
  194.  *  None
  195.  *
  196.  * Return Value:
  197.  *  None
  198.  */
  199.  
  200. STDMETHODIMP_(void) CPolylineAdviseSink::OnLineStyleChange(void)
  201.     {
  202.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  203.  
  204.     pDoc->FDirtySet(TRUE);
  205.     return;
  206.     }
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219. /*
  220.  * CImpIAdviseSink::CImpIAdviseSink
  221.  * CImpIAdviseSink::~CImpIAdviseSink
  222.  *
  223.  * Parameters (Constructor):
  224.  *  pObj            LPVOID of the object we're in.
  225.  *  punkOuter       LPUNKNOWN for delegation of IUnknown members.
  226.  */
  227.  
  228. CImpIAdviseSink::CImpIAdviseSink(LPVOID pObj, LPUNKNOWN punkOuter)
  229.     {
  230.     m_cRef=0;
  231.     m_pObj=pObj;
  232.     m_punkOuter=punkOuter;
  233.     return;
  234.     }
  235.  
  236. CImpIAdviseSink::~CImpIAdviseSink(void)
  237.     {
  238.     return;
  239.     }
  240.  
  241.  
  242.  
  243.  
  244. /*
  245.  * CImpIAdviseSink::QueryInterface
  246.  * CImpIAdviseSink::AddRef
  247.  * CImpIAdviseSink::Release
  248.  *
  249.  * Purpose:
  250.  *  IUnknown members for CImpIAdviseSink object.
  251.  */
  252.  
  253. STDMETHODIMP CImpIAdviseSink::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  254.     {
  255.     return m_punkOuter->QueryInterface(riid, ppv);
  256.     }
  257.  
  258.  
  259. STDMETHODIMP_(ULONG) CImpIAdviseSink::AddRef(void)
  260.     {
  261.     ++m_cRef;
  262.     return m_punkOuter->AddRef();
  263.     }
  264.  
  265. STDMETHODIMP_(ULONG) CImpIAdviseSink::Release(void)
  266.     {
  267.     --m_cRef;
  268.     return m_punkOuter->AddRef();
  269.     }
  270.  
  271.  
  272.  
  273.  
  274. /*
  275.  * IAdviseSink::OnDataChange
  276.  *
  277.  * Purpose:
  278.  *  Notifes the advise sink that data changed in a data object.  On
  279.  *  this message you may request a new data rendering and update your
  280.  *  displays as necessary.
  281.  *
  282.  * Parameters:
  283.  *  pFEIn           LPFORMATETC describing format that changed
  284.  *  pSTM            LPSTGMEDIUM providing the medium in which the data
  285.  *                  is provided.
  286.  *
  287.  * Return Value:
  288.  *  None
  289.  */
  290.  
  291. STDMETHODIMP_(void) CImpIAdviseSink::OnDataChange(LPFORMATETC pFEIn
  292.     , LPSTGMEDIUM pSTM)
  293.     {
  294.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pObj;
  295.  
  296.     /*
  297.      * This code copied from former CPolylineAdviseSink::OnDataChange.
  298.      * The only advise we asked for was on the Polyline native format
  299.      * which is all we'll be notified for.
  300.      */
  301.     if (NULL!=pDoc->m_pAdv)
  302.         pDoc->m_pAdv->OnDataChange(pDoc);
  303.  
  304.     pDoc->FDirtySet(TRUE);
  305.     return;
  306.     }
  307.  
  308.  
  309.  
  310.  
  311.  
  312. /*
  313.  * IAdviseSink::OnViewChange
  314.  *
  315.  * Purpose:
  316.  *  Notifes the advise sink that presentation data changed in the data
  317.  *  object to which we're connected providing the right time to update
  318.  *  displays using such presentations.
  319.  *
  320.  * Parameters:
  321.  *  dwAspect        DWORD indicating which aspect has changed.
  322.  *  lindex          LONG indicating the piece that changed.
  323.  *
  324.  * Return Value:
  325.  *  None
  326.  */
  327.  
  328. STDMETHODIMP_(void) CImpIAdviseSink::OnViewChange(DWORD dwAspect, LONG lindex)
  329.     {
  330.     return;
  331.     }
  332.  
  333.  
  334.  
  335.  
  336.  
  337. /*
  338.  * IAdviseSink::OnRename
  339.  *
  340.  * Purpose:
  341.  *  Informs the advise sink that an IOleObject has been renamed, primarily
  342.  *  when its linked.
  343.  *
  344.  * Parameters:
  345.  *  pmk             LPMONIKER providing the new name of the object
  346.  *
  347.  * Return Value:
  348.  *  None
  349.  */
  350.  
  351. STDMETHODIMP_(void) CImpIAdviseSink::OnRename(LPMONIKER pmk)
  352.     {
  353.     return;
  354.     }
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361. /*
  362.  * IAdviseSink::OnSave
  363.  *
  364.  * Purpose:
  365.  *  Informs the advise sink that the OLE object has been saved
  366.  *  persistently.  The primary purpose of this is for containers that
  367.  *  want to make optimizations for objects that are not in a saved
  368.  *  state, so on this you have to disable such optimizations.
  369.  *
  370.  * Parameters:
  371.  *  None
  372.  *
  373.  * Return Value:
  374.  *  None
  375.  */
  376.  
  377. STDMETHODIMP_(void) CImpIAdviseSink::OnSave(void)
  378.     {
  379.     return;
  380.     }
  381.  
  382.  
  383.  
  384.  
  385.  
  386. /*
  387.  * IAdviseSink::OnClose
  388.  *
  389.  * Purpose:
  390.  *  Informs the advise sink that the OLE object has closed and is
  391.  *  no longer bound in any way.  On this you typically change state
  392.  *  variables and redraw shading, etc.
  393.  *
  394.  * Parameters:
  395.  *  None
  396.  *
  397.  * Return Value:
  398.  *  None
  399.  */
  400.  
  401. STDMETHODIMP_(void) CImpIAdviseSink::OnClose(void)
  402.     {
  403.     return;
  404.     }
  405.